<?php


namespace app\common\model;


use think\Model;

class NewsModel extends Model
{
    protected $table = 'news_list';

    /**
     * 将数值类型转为 true or false 或者文字
     * @param $value
     * @return bool
     */
    public function getHavePicAttr($value)
    {
        $have_pic = [0 => false, 1 => true];
        return $have_pic[$value];
    }

    /**
     * 通过频道ID获取新闻数据
     * @param $channelId
     * @param int $limit
     * @return array|\think\Paginator
     * @throws \think\db\exception\DbException
     */
    public function getNewsList($channelId, $limit)
    {
        if (empty($channelId)) {
            return [];
        }
        return $this->where('channel_id', $channelId)->order('id', 'asc')->paginate($limit);
    }
}
